home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / CW GUSI 1.6.4 / include / GUSI.h < prev    next >
Text File  |  1995-10-08  |  9KB  |  362 lines

  1. /*********************************************************************
  2. Project    :    GUSI                -    Grand Unified Socket Interface
  3. File        :    GUSI.h            -    Socket calls
  4. Author    :    Matthias Neeracher
  5. Language    :    MPW C/C++
  6.  
  7. $Log: GUSI.h,v $
  8. Revision 1.2  1994/12/31  01:45:54  neeri
  9. Fix alignment.
  10.  
  11. Revision 1.1  1994/02/25  02:56:49  neeri
  12. Initial revision
  13.  
  14. Revision 0.15  1993/06/27  00:00:00  neeri
  15. f?truncate
  16.  
  17. Revision 0.14  1993/06/20  00:00:00  neeri
  18. Changed sa_constr_ppc
  19.  
  20. Revision 0.13  1993/02/14  00:00:00  neeri
  21. AF_PAP
  22.  
  23. Revision 0.12  1992/12/08  00:00:00  neeri
  24. getcwd()
  25.  
  26. Revision 0.11  1992/11/15  00:00:00  neeri
  27. remove netdb.h definitions
  28.  
  29. Revision 0.10  1992/09/26  00:00:00  neeri
  30. Separate dirent and stat
  31.  
  32. Revision 0.9  1992/09/12  00:00:00  neeri
  33. Hostname stuff
  34.  
  35. Revision 0.8  1992/09/07  00:00:00  neeri
  36. readlink()
  37.  
  38. Revision 0.7  1992/08/03  00:00:00  neeri
  39. sa_constr_ppc
  40.  
  41. Revision 0.6  1992/07/21  00:00:00  neeri
  42. sockaddr_atlk_sym
  43.  
  44. Revision 0.5  1992/06/26  00:00:00  neeri
  45. choose()
  46.  
  47. Revision 0.4  1992/05/18  00:00:00  neeri
  48. PPC stuff
  49.  
  50. Revision 0.3  1992/04/27  00:00:00  neeri
  51. getsockopt()
  52.  
  53. Revision 0.2  1992/04/19  00:00:00  neeri
  54. C++ compatibility
  55.  
  56. Revision 0.1  1992/04/17  00:00:00  neeri
  57. bzero()
  58.  
  59. *********************************************************************/
  60.  
  61. #ifndef _GUSI_
  62. #define _GUSI_
  63.  
  64. #include <sys/types.h>
  65.  
  66. /* Feel free to increase FD_SETSIZE as needed */
  67. #define GUSI_MAX_FD    FD_SETSIZE
  68.  
  69. #include <sys/cdefs.h>
  70. #include <compat.h>
  71. #include <sys/ioctl.h>
  72. #include <sys/fcntl.h>
  73. #include <sys/stat.h>
  74. #include <dirent.h>
  75. #include <Types.h>
  76. #include <Events.h>
  77. #include <Files.h>
  78. #include <AppleTalk.h>
  79. #include <CTBUtilities.h>
  80. #include <Packages.h>
  81. #include <PPCToolBox.h>
  82. #include <stdio.h>
  83. #include <sys/time.h>
  84. #include <sys/socket.h>
  85. #include <string.h>
  86. #include <netinet/in.h>
  87. #include <netdb.h>
  88. #include <sys/un.h>
  89. #include <unistd.h>
  90. #include <machine/endian.h>
  91.  
  92. typedef enum spin_msg {
  93.     SP_MISC,                /* some weird thing, usually just return immediately if you get this */
  94.     SP_SELECT,            /* in a select call */
  95.     SP_NAME,                /* getting a host by name */
  96.     SP_ADDR,                /* getting a host by address */
  97.     SP_STREAM_READ,    /* Stream read call */
  98.     SP_STREAM_WRITE,    /* Stream write call */
  99.     SP_DGRAM_READ,        /* Datagram read call */
  100.     SP_DGRAM_WRITE,    /* Datagram write call */
  101.     SP_SLEEP,            /* sleeping, passes ticks left to sleep */
  102.     SP_AUTO_SPIN        /* Autospin, passes argument to SpinCursor */
  103. } spin_msg;
  104.  
  105. typedef int (*GUSISpinFn)(spin_msg msg, long param);
  106. typedef void (*GUSIEvtHandler)(EventRecord * ev);
  107. typedef GUSIEvtHandler    GUSIEvtTable[24];
  108.  
  109. /*
  110.  * Address families, defined in sys/socket.h
  111.  *
  112.  
  113. #define    AF_UNSPEC         0        // unspecified
  114. #define    AF_UNIX             1        // local to host (pipes, portals)
  115. #define    AF_INET             2        // internetwork: UDP, TCP, etc.
  116. #define    AF_CTB             3        // Apple Comm Toolbox (not yet supported)
  117. #define    AF_FILE             4        // Normal File I/O (used internally)
  118. #define    AF_PPC             5        // PPC Toolbox
  119. #define    AF_PAP             6        // Printer Access Protocol (client only)
  120. #define    AF_APPLETALK    16        // Apple Talk
  121.  
  122. */
  123.  
  124. #define    ATALK_SYMADDR 272        /* Symbolic Address for AppleTalk             */
  125.  
  126. /*
  127.  * Some Implementations of GUSI require you to call GUSISetup for the
  128.  * socket families you'd like to have defined. It's a good idea to call
  129.  * this for *all* implementations.
  130.  *
  131.  * GUSIDefaultSetup() will include all socket families.
  132.  *
  133.  * Never call any of the GUSIwithXXX routines directly.
  134.  */
  135.  
  136. __BEGIN_DECLS
  137. void GUSIwithAppleTalkSockets();
  138. void GUSIwithInternetSockets();
  139. void GUSIwithPAPSockets();
  140. void GUSIwithPPCSockets();
  141. void GUSIwithUnixSockets();
  142. void GUSIwithSIOUXSockets();
  143. void GUSIwithMPWSockets();
  144.  
  145. void GUSISetup(void (*socketfamily)());
  146. void GUSIDefaultSetup();
  147. __END_DECLS
  148. /*
  149.  * Types,  defined in sys/socket.h
  150.  *
  151.  
  152. #define    SOCK_STREAM         1        // stream socket 
  153. #define    SOCK_DGRAM         2        // datagram socket
  154.  
  155. */
  156.  
  157. #if defined(powerc) || defined (__powerc)
  158. #pragma options align=mac68k
  159. #endif
  160.  
  161. /*
  162.  * Defined in sys/un.h
  163.  *
  164.  
  165. struct sockaddr_un {
  166.     short        sun_family;
  167.     char         sun_path[108];
  168. };
  169.  
  170. */
  171.  
  172. #ifndef PRAGMA_ALIGN_SUPPORTED
  173. #error Apple had some fun with the conditional macros again
  174. #endif
  175.  
  176. #if PRAGMA_ALIGN_SUPPORTED
  177. #pragma options align=mac68k
  178. #endif
  179.  
  180. struct sockaddr_atlk {
  181.     short            family;
  182.     AddrBlock    addr;
  183. };
  184.  
  185. struct sockaddr_atlk_sym {
  186.     short            family;
  187.     EntityName    name;
  188. };
  189.  
  190. struct sockaddr_ppc {
  191.     short                    family;
  192.     LocationNameRec    location;
  193.     PPCPortRec            port;
  194. };
  195.  
  196. /* Definitions for choose() */
  197.  
  198. #define     CHOOSE_DEFAULT    1        /*    Use *name as default name                        */
  199. #define    CHOOSE_NEW        2        /* Choose new entity name, not existing one    */
  200. #define    CHOOSE_DIR        4        /* Choose a directory name, not a file         */
  201.  
  202. typedef struct {
  203.     short            numTypes;
  204.     SFTypeList    types;
  205. } sa_constr_file;
  206.  
  207. typedef struct {
  208.     short            numTypes;
  209.     NLType        types;
  210. } sa_constr_atlk;
  211.  
  212. /* Definitions for sa_constr_ppc */
  213.  
  214. #define PPC_CON_NEWSTYLE        0x8000    /* Required */
  215. #define PPC_CON_MATCH_NAME        0x0001    /* Match name */
  216. #define PPC_CON_MATCH_TYPE     0x0002     /* Match port type */
  217. #define PPC_CON_MATCH_NBP        0x0004    /* Match NBP type */
  218.  
  219. typedef struct    {
  220.     short            flags;
  221.     Str32            nbpType;
  222.     PPCPortRec    match;
  223. } sa_constr_ppc;
  224.  
  225. #if PRAGMA_ALIGN_SUPPORTED
  226. #pragma options align=reset
  227. #endif
  228.  
  229. __BEGIN_DECLS
  230. /* 
  231.  * IO/Socket stuff, defined elsewhere (unistd.h, sys/socket.h
  232.  *
  233.  
  234. int socket(int domain, int type, short protocol);
  235. int bind(int s, void *name, int namelen);
  236. int connect(int s, void *addr, int addrlen);
  237. int listen(int s, int qlen);
  238. int accept(int s, void *addr, int *addrlen);
  239. int close(int s);
  240. int read(int s, char *buffer, unsigned buflen);
  241. int readv(int s, struct iovec *iov, int count);
  242. int recv(int s, void *buffer, int buflen, int flags);
  243. int recvfrom(int s, void *buffer, int buflen, int flags, void *from, int *fromlen);
  244. int recvmsg(int s,struct msghdr *msg,int flags);
  245. int write(int s, const char *buffer, unsigned buflen);
  246. int writev(int s, struct iovec *iov, int count);
  247. int send(int s, void *buffer, int buflen, int flags);
  248. int sendto (int s, void *buffer, int buflen, int flags, void *to, int tolen);
  249. int sendmsg(int s,struct msghdr *msg,int flags);
  250. int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
  251. int getdtablesize(void);
  252. int getsockname(int s, void *name, int *namelen);
  253. int getpeername(int s, struct sockaddr *name, int *namelen);
  254. int shutdown(int s, int how);
  255. int fcntl(int s, unsigned int cmd, int arg);
  256. int dup(int s);
  257. int dup2(int s, int s1);
  258. int ioctl(int d, unsigned int request, long *argp);
  259. int getsockopt(int s, int level, int optname, char *optval, int * optlen);
  260. int setsockopt(int s, int level, int optname, char *optval, int optlen);
  261. int isatty(int);
  262. int remove(const char *filename);
  263. int rename(const char *oldname, const char *newname);
  264. int creat(const char*);
  265. int faccess(char*, unsigned int, long*);
  266. long lseek(int, long, int);
  267. int open(const char*, int);
  268. int unlink(char*);
  269. int symlink(char* linkto, char* linkname);
  270. int readlink(char* path, char* buf, int bufsiz);
  271. int truncate(char *path, long length);
  272. int ftruncate(int fd, long length);
  273. int chdir(char * path);
  274. int mkdir(char * path);
  275. int rmdir(char * path);
  276. char * getcwd(char * buf, int size);
  277. */
  278.  
  279. /* 
  280.  * Defined in stdio.h
  281.  */
  282.  
  283. #ifdef __MWERKS__
  284. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  285. #endif
  286.  
  287. void fgetfileinfo (char *filename, unsigned long * creator, unsigned long * type);
  288.  
  289. #ifdef __MWERKS__
  290. FILE *fdopen(int fd, const char *mode);
  291. int fwalk(int (*func)(FILE * stream));
  292. #endif
  293.  
  294. int choose(
  295.         int         domain,
  296.         int         type,
  297.         char *     prompt,
  298.         void *     constraint,
  299.         int         flags,
  300.         void *     name,
  301.         int *     namelen);
  302.  
  303. /* 
  304.  * Hostname routines, defined in netdb.h
  305.  *
  306.  
  307. struct hostent * gethostbyname(char *name);
  308. struct hostent * gethostbyaddr(struct in_addr *addrP, int, int);
  309. int gethostname(char *machname, long buflen);
  310. struct servent * getservbyname (char * name, char * proto);
  311. struct protoent * getprotobyname(char * name);
  312.  
  313. */
  314.  
  315. char * inet_ntoa(struct in_addr inaddr);
  316. struct in_addr inet_addr(char *address);
  317.  
  318. /* 
  319.  * GUSI supports a number of hooks. Every one of them has a different prototype, but needs
  320.  * to be passed as a GUSIHook
  321.  */
  322.  
  323. typedef enum {
  324.     GUSI_SpinHook,    /* A GUSISpinFn, to be called when a call blocks */
  325.     GUSI_ExecHook /* Boolean (*hook)(const GUSIFileRef & ref), decides if file is executable */
  326. } GUSIHookCode;
  327.  
  328. typedef void (*GUSIHook)(void);
  329. void GUSISetHook(GUSIHookCode code, GUSIHook hook);
  330. GUSIHook GUSIGetHook(GUSIHookCode code);
  331.  
  332. /* 
  333.  * What to do when a routine blocks
  334.  */
  335.  
  336. /* Defined for compatibility */
  337. #define GUSISetSpin(routine)    GUSISetHook(GUSI_SpinHook, (GUSIHook)routine)
  338. #define GUSIGetSpin()            (GUSISpinFn) GUSIGetHook(GUSI_SpinHook)
  339.  
  340. int GUSISetEvents(GUSIEvtTable table);
  341. GUSIEvtHandler * GUSIGetEvents(void);
  342.  
  343. extern GUSIEvtHandler    GUSISIOWEvents[];
  344.  
  345. #define SIGALRM    6
  346.  
  347. /* 
  348.  * BSD memory routines, defined in compat.h
  349.  *
  350.  
  351. #define index(a, b)                        strchr(a, b)
  352. #define rindex(a, b)                        strrchr(a, b)
  353. #define bzero(from, len)                 memset(from, 0, len)
  354. #define bcopy(from, to, len)            memcpy(to, from, len)
  355. #define bcmp(s1, s2, len)                memcmp(s1, s2, len)
  356. #define bfill(from, len, x)            memset(from, x, len)
  357.  
  358.  */
  359.  
  360. __END_DECLS
  361.  
  362. #endif /* !_GUSI_ */